﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shared.Model
{
    /// <summary>
    /// 结果集基类
    /// </summary>
    public class ResultSet
    {
        public bool result { get; set; }
        public string message { get; set; }

        public ResultSet(bool ret = true, string msg = "")
        {
            result = ret;
            message = msg;
        }

        public virtual void Success(string msg)
        {
            result = true;
            message = msg;
        }

        public virtual void Error(string msg)
        {
            result = false;
            message = msg;
        }
    }
    /// <summary>
    /// 结果集--一个对象
    /// </summary>
    /// <typeparam name="T">对象1</typeparam>
    public class ResultSet<T> : ResultSet
        where T : new()//约束类必须有一个无参数构造函数
    {
        public T value { get; set; }

        public ResultSet()
            : base()
        {
            value = new T();
        }
        public ResultSet(bool ret, string msg)
            : base(ret, msg)
        {
            value = new T();
        }

        public virtual void Success(string msg, T value)
        {
            base.Success(msg);
            this.value = value;
        }
    }
    /// <summary>
    /// 结果集两个对象
    /// </summary>
    /// <typeparam name="T">对象1</typeparam>
    /// <typeparam name="V">对象2</typeparam>
    public class ResultSet<T, V> : ResultSet<T>
        where T : new()
        where V : new()
    {
        //如果不修改ResultSet<T,V>为ResultSet2<T,V>编译会不能通过
        public V value2 { get; set; }

        public ResultSet()
            : base()
        {
            value2 = new V();
        }
        public ResultSet(bool ret, string msg)
            : base(ret, msg)
        {
            value2 = new V();
        }
        public virtual void Success(string msg, T value, V value2)
        {
            base.Success(msg, value);
            this.value2 = value2;
        }
    }
}
